package com.clw.weblogin.controller;

import com.clw.weblogin.common.entity.ResultEntity;
import com.clw.weblogin.entity.JieKuanLiuShui;
import com.clw.weblogin.service.JieKuanLiuShuiService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

@Controller
@RequestMapping("/jiekuanliushui")
public class JieKuanLiuShuiController {
    @Autowired
    JieKuanLiuShuiService service;

    @ResponseBody
    @RequestMapping("/insert")
    public ResultEntity insert(String id,String name, String usernumber, String book, String phone, String banknumber, double cunkuanmoney, String cunkuandate
            , double lilv, String cunkuantype, String jiesuandate, String beizhu, String caozuoren, String departmentid, int jiesuanzhouqi, String caozuoleixing, double lixi, String enddate, String nowenddate) throws Exception {
        ResultEntity entity = new ResultEntity();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        JieKuanLiuShui bean = new JieKuanLiuShui();
        bean.setJiekuanid(Integer.valueOf(id));
        bean.setName(name);
        bean.setUsername(usernumber);
        bean.setBook(book);
        bean.setPhone(phone);
        bean.setBanknumber(banknumber);
        bean.setCunkuandate(sdf.parse(cunkuandate));
        bean.setCunkuantype(cunkuantype);
        bean.setJiesuandate(sdf.parse(jiesuandate));
        bean.setJiesuanzhouqi(jiesuanzhouqi);
        bean.setCaozuoleixing(caozuoleixing);
        bean.setCunkuanmoney(cunkuanmoney);
        bean.setBeizhu(beizhu);
        if (enddate == "") {
            bean.setQishu(cunkuandate + "-" + nowenddate);
        } else {
            bean.setQishu(enddate + "-" + nowenddate);
        }
        bean.setLilv(lilv);
        bean.setCaozuodate(new Date());
        bean.setDepartmentid(departmentid);
        bean.setCaozuoren(caozuoren);
        bean.setType(1);
        bean.setLixi(lixi);
        entity = service.insert(bean,nowenddate);
        return entity;
    }
    @ResponseBody
    @RequestMapping("/selectByid")
    public ResultEntity selectByid(String departmentid,int jiekuanid,int page, @RequestParam(required = false, defaultValue = "5") int limit){
        ResultEntity entity=  new ResultEntity();
        JieKuanLiuShui jieKuanLiuShui=new JieKuanLiuShui();
        jieKuanLiuShui.setJiekuanid(jiekuanid);
        jieKuanLiuShui.setDepartmentid(departmentid);
        entity=service.selectByExample(jieKuanLiuShui,page,limit);
        return entity;
    }

}

